import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../../pages/skddl2/skddl_info_huizhi.dart';

import '../../helper/Helper.dart';
import '../../model/skddl2.dart';
import '../../pages/SKDDL2/sdddl_authorty.dart';

import 'package:shared_preferences/shared_preferences.dart';

import '../../helper/uidata.dart';

import 'skddl_info.dart';

class SKDDL2InfoHomePage extends StatefulWidget {
  @override
  SKDDL2InfoHomePage(this.s1, this.callback);
  final SKDDL2 s1;
  final RefrushCallback callback;

  createState() => new SKDDL2PageState();
}

class SKDDL2PageState extends State<SKDDL2InfoHomePage> {
//  定义底部导航列表
  final List<BottomNavigationBarItem> bottomTabs = [
    new BottomNavigationBarItem(
        icon: new Icon(Icons.device_hub), label: ('调度令签发')),
    new BottomNavigationBarItem(
        icon: new Icon(FontAwesomeIcons.file), label: ('执行情况回执')),
  ];

  Widget getBody(int i) {
    if (i == 0) return SKDDL2InfoPage(widget.s1, widget.callback);
    if (i == 1) return SKDDL2InfoHuiZhiPage(widget.s1, widget.callback);
    return new Container();
  }

  final titleList = ["调度令签发", "执行情况回执"];
  int currentIndex = 0; //当前索引
  late Widget currentPage; //当前页面

  @override
  void initState() {
    super.initState();
    currentPage = getBody(0);
  }

  @override
  Widget build(BuildContext context) {
    exitLogin(BuildContext context) async {
      UIData.CurrentUser = null;
      SharedPreferences prefs = await SharedPreferences.getInstance();
      prefs.remove("username");
      prefs.remove("password");
      Navigator.of(context)
          .pushNamedAndRemoveUntil(UIData.loginRoute, ModalRoute.withName('/'));
    }

    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        // title: bottomTabs[currentIndex].title,
        title: Text("调度令详情"),

        // leading: Icon(Icons.menu),
      ),
      bottomNavigationBar: new BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: currentIndex,
          items: bottomTabs,
          fixedColor: Colors.blue,
          onTap: (index) {
            setState(() {
              currentIndex = index;
              currentPage = getBody(currentIndex);
            });
          }),
      body: currentPage,
    );
  }
}
